import java.io.*;
import java.net.*;
import java.util.Random;
import java.util.Scanner;
public class Client {
    private static final String SERVER_ADDRESS = "127.0.0.1";
    private static final int SERVER_PORT = 12345;

    public static void main(String[] args) {
        try (Socket socket = new Socket(SERVER_ADDRESS, SERVER_PORT);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {

            Scanner scanner = new Scanner(System.in);
            System.out.println("客户端启动，准备发送数据...");

            // 逐步增加数据量
            for (int i = 4; i < 1024; i += 4) {
                String message = generateRandomString(i);
                out.println(message);
                System.out.println("发送：" + message);
                String response = in.readLine();
                System.out.println("收到服务器回送：" + response);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static  String generateRandomString(int length) {
        String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        StringBuilder result = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < length; i++) {
            result.append(characters.charAt(random.nextInt(characters.length())));
        }
        return result.toString();
    }
}
